/*
 *-----------------------------------------------------------------------------
 *
 * TUMLEditorCaller.java
 *
 * This file was created from IUMLEditor.idl
 * by the Simple JavRMI backend.
 *
 * Copyright 2008-2010, Evgeny Alexeyev
 * Licensed under the EPL - v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *-----------------------------------------------------------------------------
 */

package com.googlecode.umlsynch.rpc;

import java.io.*;

import com.googlecode.umlsynch.rpc.base.TIOHandler;

import com.googlecode.umlsynch.rpc.base.IDebug;

import com.googlecode.umlsynch.rpc.base.TDebug;

import com.googlecode.umlsynch.rpc.TWorkingAreaDescriptor;

import com.googlecode.umlsynch.rpc.TPointDescriptor;

import com.googlecode.umlsynch.rpc.TFileDescriptor;

import com.googlecode.umlsynch.rpc.TPacketDescriptor;

import com.googlecode.umlsynch.rpc.TEnumDescriptor;

import com.googlecode.umlsynch.rpc.TClassDescriptor;

import com.googlecode.umlsynch.rpc.IUMLEditor;


public class TUMLEditorCaller implements IUMLEditor
{
  TIOHandler handler;
  TDebug debug;
  
  public TUMLEditorCaller(TIOHandler hdl, IDebug dbg) {
    handler = hdl;
    debug = new TDebug(dbg);
  }
  
  @Override
  public TWorkingAreaDescriptor GetWorkingArea() {
    if (!handler.connect())
      return null;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IUMLEditor"));
      handler.getObjectOutputStream().writeObject(new String("GetWorkingArea"));
      
      TWorkingAreaDescriptor result = null;
      data = handler.readString();
      if (data.equals("TWorkingAreaDescriptor")) {
        result = (TWorkingAreaDescriptor) handler.getObjectInputStream().readObject();
      } else {
        debug.Error("Recieved wrong parameter type:" + data + " expected TWorkingAreaDescriptor");
        throw new ClassNotFoundException();
      }
      
      return result;
    }
    catch (IOException e) {
    }
    catch (ClassNotFoundException e) {
    }
    
    handler.close();
    return null;
  }; // GetWorkingArea
  
  @Override
  public void CreatePacketOnDiagram(TPacketDescriptor desc, TPointDescriptor position) {
    if (!handler.connect())
      return;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IUMLEditor"));
      handler.getObjectOutputStream().writeObject(new String("CreatePacketOnDiagram"));
      
      handler.getObjectOutputStream().writeObject(new String("TPacketDescriptor"));
      handler.getObjectOutputStream().writeObject(desc);
      
      handler.getObjectOutputStream().writeObject(new String("TPointDescriptor"));
      handler.getObjectOutputStream().writeObject(position);
      
    }
    catch (IOException e) {
    }
    
    handler.close();
  }; // CreatePacketOnDiagram
  
  @Override
  public void CreateClassOnDiagram(TClassDescriptor desc, TPointDescriptor position) {
    if (!handler.connect())
      return;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IUMLEditor"));
      handler.getObjectOutputStream().writeObject(new String("CreateClassOnDiagram"));
      
      handler.getObjectOutputStream().writeObject(new String("TClassDescriptor"));
      handler.getObjectOutputStream().writeObject(desc);
      
      handler.getObjectOutputStream().writeObject(new String("TPointDescriptor"));
      handler.getObjectOutputStream().writeObject(position);
      
    }
    catch (IOException e) {
    }
    
    handler.close();
  }; // CreateClassOnDiagram
  
  @Override
  public void CreateEnumOnDiagram(TEnumDescriptor desc, TPointDescriptor position) {
    if (!handler.connect())
      return;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IUMLEditor"));
      handler.getObjectOutputStream().writeObject(new String("CreateEnumOnDiagram"));
      
      handler.getObjectOutputStream().writeObject(new String("TEnumDescriptor"));
      handler.getObjectOutputStream().writeObject(desc);
      
      handler.getObjectOutputStream().writeObject(new String("TPointDescriptor"));
      handler.getObjectOutputStream().writeObject(position);
      
    }
    catch (IOException e) {
    }
    
    handler.close();
  }; // CreateEnumOnDiagram
  
}; // IUMLEditor

